home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 16 / CU Amiga Magazine's Super CD-ROM 16 (1997-10-16)(EMAP Images)(GB)[!][issue 1997-11].iso / CUCD / Utilities / Datatypes / acbm / classbase.c < prev    next >
C/C++ Source or Header  |  1997-05-30  |  8KB  |  304 lines

  1.  
  2. /*
  3. **
  4. **  $VER: classbase.c 1.1 (30.5.97)
  5. **  acbm.datatype 1.1
  6. **
  7. **  Library routines for a DataTypes class
  8. **
  9. **  Written 1996/97 by Roland 'Gizzy' Mainz
  10. **  Original example source from David N. Junod
  11. **
  12. */
  13.  
  14.  
  15. /* main includes */
  16. #include "classbase.h"
  17.  
  18.  
  19. /****** acbm.datatype/--datasheed-- ******************************************
  20. *
  21. *   NAME
  22. *       acbm.datatype -- data type for IFF ACBM pictures
  23. *
  24. *   SUPERCLASS
  25. *       picture.datatype
  26. *
  27. *   DESCRIPTION
  28. *       The acbm datatype, a sub-class of the picture.datatype, is
  29. *       used to load and save IFF ACBM pictures.
  30. *
  31. *       This class is offloaded from the datatypes.library V45 example code
  32. *       and is the reference implementation of a picture.datatype subclass
  33. *       (using V42 API) which supports saving in it's local format (as used
  34. *       by converters like "DTConvert").
  35. *
  36. *   METHODS
  37. *       OM_NEW -- Create a new picture object from a description file. The
  38. *           source may only be a file.
  39. *
  40. *       OM_UPDATE -- Perform an ICM_CHECKLOOP check, and if succesfull, the
  41. *           method will be executed like OM_SET downstairs.
  42. *
  43. *       OM_SET -- Pass msg to superclass and call GM_RENDER if retval from
  44. *           superclass was != 0UL.
  45. *
  46. *       DTM_WRITE -- Save data in local (IFF ACBM) or superclass (IFF ILBM)
  47. *           format.
  48. *
  49. *       All other methods are passed unchanged to superclass.
  50. *
  51. *   ATTRIBUTES
  52. *       Following attributes are set by the object and are READ-ONLY for
  53. *       applications (if the datatype is used for saving (e.g. the
  54. *       application creates an empty acbm.datatype object and fills
  55. *       in some required atrributes as shown in the "DTConvert" example),
  56. *       these attributes are used by the encoder to create an IFF ACBM 
  57. *       picture file):
  58. *
  59. *       DTA_ObjName         -- Set by an IFF NAME chunk. If missing,
  60. *                              DTA_ObjName will take DTA_Name's value.
  61. *       DTA_ObjAuthor       -- Set by an IFF AUTH chunk.
  62. *       DTA_ObjAnnotation   -- Set by an IFF ANNO chunk.
  63. *       DTA_ObjCopyright    -- Set by an IFF (C) chunk.
  64. *       DTA_ObjVersion      -- Set by an IFF FVER chunk.
  65. *       DTA_NominalHoriz    -- Same as PDTA_BitMapHeader -> bmh_Width
  66. *       DTA_NominalVert     -- Same as PDTA_BitMapHeader -> bmh_Height
  67. *       PDTA_ModeID         -- Set by an IFF ILBM/ACBM CAMG chunk. If missing
  68. *                              or the value here is 0, BestModeIDA will
  69. *                              select a value based on BMHD information.
  70. *       PDTA_NumColors      -- Set by IFF ILBM/ACBM CMAP chunk
  71. *       PDTA_ColorRegisters -- Set by IFF ILBM/ACBM CMAP chunk
  72. *       PDTA_CRegs          -- Set by IFF ILBM/ACBM CMAP chunk
  73. *       PDTA_BitMap         -- The image itself, created from IFF ACBM ABIT
  74. *                              chunk and some IFF ILBM/ACBM BMHD infos.
  75. *
  76. *   BUGS
  77. *       - Images with more than 8 planes causes crashes (because AllocBitMap
  78. *         allocates only 8 plane pointers).
  79. *
  80. *   TODO
  81. *       - Fixing the bugs above.
  82. *
  83. *       - Add GRAB support (e.g. IFF ILBM GRAB chunk and matching PDTA_Grab
  84. *         chunk).
  85. *
  86. *   HISTORY
  87. *       V1.1
  88. *         First public release.
  89. *
  90. *   NOTES
  91. *
  92. *   SEE ALSO
  93. *       picture.datatype
  94. *
  95. *******************************************************************************
  96. *
  97. */
  98.  
  99.  
  100. /****** acbm.datatype/--input_format-- ****************************************
  101. *
  102. *    NAME
  103. *        IFF ACBM -- Amiga Contiguous BitMap
  104. *
  105. *    DESCRIPTION
  106. *        FORM ACBM has the same format as FORM ILBM except the normal BODY
  107. *        chunk (Interleaved Bitmap) is replaced by an ABIT chunk (Amiga
  108. *        BITplanes).
  109. *
  110. *        The ABIT chunk contains continous bitplane data. The chunk contains
  111. *        sequential data fro planes 0 through plane i.
  112. *
  113. *    SEE ALSO
  114. *        - ARKM Devices: IFF part
  115. *
  116. *        - iffparse.library autodocs
  117. *
  118. *        - AmigaBasic LoadACBM/SaveACBM
  119. *
  120. *    THANKS TO
  121. *        Carolyn Scheppner (CBM) for creating this format
  122. *
  123. *******************************************************************************
  124. *
  125. */
  126.  
  127.  
  128.  
  129. /*****************************************************************************/
  130.  
  131. DISPATCHERFLAGS
  132. struct IClass *ObtainACBMEngine( REGA6 struct ClassBase *cb )
  133. {
  134.     return( (cb -> cb_Lib . cl_Class) );
  135. }
  136.  
  137. /*****************************************************************************/
  138.  
  139. DISPATCHERFLAGS
  140. struct Library *LibInit( REGD0 struct ClassBase *cb, REGA0 BPTR seglist, REGA6 struct ExecBase *sysbase )
  141. {
  142.     cb -> cb_SegList = seglist;
  143.     cb -> cb_SysBase = sysbase;
  144.  
  145.     InitSemaphore( (&(cb -> cb_Lock)) );
  146.  
  147.     if( (cb -> cb_SysBase -> LibNode . lib_Version) >= 39UL )
  148.     {
  149.       /* Obtain ROM libs */
  150.       if( cb -> cb_IntuitionBase = OpenLibrary( "intuition.library", 39UL ) )
  151.       {
  152.         if( cb -> cb_GfxBase = OpenLibrary( "graphics.library", 39UL ) )
  153.         {
  154.           if( cb -> cb_DOSBase = OpenLibrary( "dos.library", 39UL ) )
  155.           {
  156.             if( cb -> cb_IFFParseBase = OpenLibrary( "iffparse.library", 39UL ) )
  157.             {
  158.               if( cb -> cb_UtilityBase = OpenLibrary( "utility.library", 39UL ) )
  159.               {
  160.                 return( (&(cb -> cb_Lib . cl_Lib)) );
  161.  
  162. #ifdef COMMENTED_OUT
  163.                 CloseLibrary( UtilityBase );
  164. #endif /* COMMENTED_OUT */
  165.               }
  166.  
  167.               CloseLibrary( IFFParseBase );
  168.             }
  169.  
  170.             CloseLibrary( DOSBase );
  171.           }
  172.  
  173.           CloseLibrary( GfxBase );
  174.         }
  175.  
  176.         CloseLibrary( IntuitionBase );
  177.       }
  178.     }
  179.  
  180.     return( NULL );
  181. }
  182.  
  183. /*****************************************************************************/
  184.  
  185. DISPATCHERFLAGS
  186. LONG LibOpen( REGA6 struct ClassBase *cb )
  187. {
  188.     LONG retval = (LONG)cb;
  189.     BOOL success = TRUE;
  190.  
  191.     ObtainSemaphore( (&(cb -> cb_Lock)) );
  192.  
  193.     /* Use an internal use counter */
  194.     cb -> cb_Lib . cl_Lib . lib_OpenCnt++;
  195.     cb -> cb_Lib . cl_Lib . lib_Flags &= ~LIBF_DELEXP;
  196.  
  197.     if( (cb -> cb_Lib . cl_Lib . lib_OpenCnt) == 1U )
  198.     {
  199.       if( (cb -> cb_Lib . cl_Class) == NULL )
  200.       {
  201.         success = FALSE;
  202.  
  203.         if( cb -> cb_DataTypesBase = OpenLibrary( "datatypes.library", 39UL ) )
  204.         {
  205.           if( cb -> cb_SuperClassBase = OpenLibrary( "datatypes/picture.datatype", 39UL ) )
  206.           {
  207.             if( cb -> cb_Lib . cl_Class = initClass( cb ) )
  208.             {
  209.               success = TRUE;
  210.             }
  211.           }
  212.         }
  213.       }
  214.     }
  215.  
  216.     if( !success )
  217.     {
  218.       CloseLibrary( (cb -> cb_SuperClassBase) );
  219.       CloseLibrary( (cb -> cb_DataTypesBase) );
  220.  
  221.       cb -> cb_DataTypesBase = cb -> cb_SuperClassBase = NULL;
  222.  
  223.       (cb -> cb_Lib . cl_Lib . lib_OpenCnt)--;
  224.  
  225.       retval = 0L;
  226.     }
  227.  
  228.     ReleaseSemaphore( (&(cb -> cb_Lock)) );
  229.  
  230.     return( retval );
  231. }
  232.  
  233. /*****************************************************************************/
  234.  
  235. DISPATCHERFLAGS
  236. LONG LibClose( REGA6 struct ClassBase *cb )
  237. {
  238.     LONG retval = 0L;
  239.  
  240.     ObtainSemaphore( (&(cb -> cb_Lock)) );
  241.  
  242.     if( cb -> cb_Lib . cl_Lib . lib_OpenCnt )
  243.     {
  244.       (cb -> cb_Lib . cl_Lib . lib_OpenCnt)--;
  245.     }
  246.  
  247.     if( ((cb -> cb_Lib . cl_Lib . lib_OpenCnt) == 0U) && (cb -> cb_Lib . cl_Class) )
  248.     {
  249.       if( FreeClass( (cb -> cb_Lib . cl_Class) ) )
  250.       {
  251.         cb -> cb_Lib . cl_Class = NULL;
  252.  
  253.         CloseLibrary( (cb -> cb_SuperClassBase) );
  254.         CloseLibrary( (cb -> cb_DataTypesBase) );
  255.       }
  256.       else
  257.       {
  258.         cb -> cb_Lib . cl_Lib . lib_Flags |= LIBF_DELEXP;
  259.       }
  260.     }
  261.  
  262.     ReleaseSemaphore( (&(cb -> cb_Lock)) );
  263.  
  264.     if( cb -> cb_Lib . cl_Lib . lib_Flags & LIBF_DELEXP )
  265.     {
  266.       retval = LibExpunge( cb );
  267.     }
  268.  
  269.     return( retval );
  270. }
  271.  
  272. /*****************************************************************************/
  273.  
  274. DISPATCHERFLAGS
  275. LONG LibExpunge( REGA6 struct ClassBase *cb )
  276. {
  277.     BPTR seg;
  278.  
  279.     if( cb -> cb_Lib . cl_Lib . lib_OpenCnt )
  280.     {
  281.       cb -> cb_Lib . cl_Lib . lib_Flags |= LIBF_DELEXP;
  282.  
  283.       seg = NULL;
  284.     }
  285.     else
  286.     {
  287.       Remove( (&(cb -> cb_Lib . cl_Lib . lib_Node)) );
  288.  
  289.       seg = cb -> cb_SegList;
  290.  
  291.       CloseLibrary( (cb -> cb_UtilityBase) );
  292.       CloseLibrary( (cb -> cb_IFFParseBase) );
  293.       CloseLibrary( (cb -> cb_DOSBase) );
  294.       CloseLibrary( (cb -> cb_GfxBase) );
  295.       CloseLibrary( (cb -> cb_IntuitionBase) );
  296.  
  297.       FreeMem( (APTR)((ULONG)(cb) - (ULONG)(cb -> cb_Lib . cl_Lib . lib_NegSize)), (ULONG)((cb -> cb_Lib . cl_Lib . lib_NegSize) + (cb -> cb_Lib . cl_Lib . lib_PosSize)) );
  298.     }
  299.  
  300.     return( (LONG)seg );
  301. }
  302.  
  303.  
  304.